<?php
    $top_menu_1 = FALSE;
    $top_menu_2 = FALSE;
    $top_menu_3 = TRUE;
    $top_menu_4 = FALSE;
    $top_menu_5 = FALSE;
    $top_menu_6 = FALSE;
    $top_menu_7 = FALSE;
    include('header.php');
    include('sidebar2.php');
    
    //$m_levelx = 0;
    //if(isset($_SESSION['m_level'])){
    //    if($_SESSION['m_level']==1){
    //        $m_levelx = 1;
    //    }else{
    //        $m_levelx = 3;
    //    }
    //}
    
    if(!isset($_GET['id']) AND !in_array($_GET['id'],array(1,2))){
        $pc_group = 2;
    }else{
        $pc_group = $_GET['id'];
    }
    
    if($pc_group==1){
        $pageTitle = 'GENERAL COLLECTION';
    }else{
        $pageTitle = 'NEW COLLECTION';
    }
    
    $rss = $db->query("SELECT * FROM hs_collection WHERE pc_group=$pc_group AND pc_active=1 ORDER BY pc_id DESC");
    $collectionList = '';
    $collectGroupList = '';
    $y = 0;
    while ($line = $db->fetchNextObject($rss)){
        $rss2 = $db->query('SELECT * FROM hs_product WHERE pc_id='.$line->pc_id.' AND p_active=1 ORDER BY pc_id DESC');
        if($db->numRows($rss2)>0){
            $i = 0;
            while ($line2 = $db->fetchNextObject($rss2)){
                if($i==0){
                    if($y==0){
                        if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img)){
                            $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img;
                        }else if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img))){
                            $fImg = URL.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img);
                        }else{
                            $fImg = URL.'/images/noimg.jpg';
                        }
                        $fTitle = $line->pc_name;
                        $fSlogan = $line->pc_slogan;
                        $fDetail = $line->pc_detail;
                        $fId = $line2->p_id;
                    }
                    
                    $class = '';
                    if((($y)%4)==0){
                        $class='gallery_list_first';
                    }
                    
                    if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img)){
                        $productImg = URL.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img;
                    }else if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img))){
                        $productImg = URL.'/images/products/product/'.$line2->p_id.'/'.str_replace('.JPG','.jpg',$line2->p_img);
                    }else{
                        $productImg = URL.'/images/noimg.jpg';
                    }
                    
                    $collectionList .= <<<collectionList
                        <div class="gallery_list {$class}">
                            <img src="{$productImg}" id="{$line2->pc_id}" alt="{$line2->p_name}" title="{$line->pc_slogan}" class="img_link select_coll_id" />
                            <p>{$line->pc_name}</p>
                        </div>
collectionList;
                }
                
                //if($y){
                    if($line2->p_img!='' AND file_exists(APPPATH.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img)){
                        $productImg = URL.'/images/products/product/'.$line2->p_id.'/'.$line2->p_img;
                    }else{
                        $productImg = URL.'/images/noimg.jpg';
                    }
                    
                    $collectGroupList .= '<li id="'.$line2->p_id.'"><img src="'.$productImg.'" alt="'.$line2->p_name.'" title="'.$line2->p_name.'" class="img_link" /></li>';
                //}
                $i++;
            }
            $y++;
        }
    }
?>
            <div id="main_content" class="gallery_content">
                <img src="images/gallery_title.jpg" alt="Gallery" id="gallery_title" />
                
                <div id="gallery_nav">
                    <a href="gallery.php?id=2" title="New Collection">New Collection</a>
                    <a href="gallery.php?id=1" title="General Collection">General Collection</a>
                </div>
                
                <div id="gallery_coll_name">
                    <h2><a href="" title="<?php echo $pageTitle; ?>"><?php echo $pageTitle; ?></a></h2>
                </div>
                
                <div id="gallery_coll_detail<?php if($y==0){ echo '_';} ?>">
                    <div id="gallery_coll_detail_x" <?php if($y==0){ echo 'class="display_none"';} ?>>
                        <div id="gallery_coll_detail_img">
                            <a href="<?php echo $fImg; ?>" title="<?php echo $fTitle; ?>" class="afancybox"><img src="<?php echo $fImg; ?>" alt="<?php echo $fTitle; ?>" /></a>
                            <p>Click to enlarge.</p>
                        </div>
                        <div id="gallery_coll_detail_">
                            <h2><?php echo $fTitle; ?></h2>
                            <h3><?php echo $fSlogan; ?></h3>
                            <div id="gallery_coll_detail_desc">
                                <div class="scrollbar">
                                    <div class="track">
                                        <div class="thumb">
                                            <div class="end"></div>
                                        </div>
                                    </div>
                                </div>
                                <div class="viewport">
                                    <div class="overview">
                                        <?php echo $fDetail; ?>
                                    </div>
                                </div>
                            </div>
                            <div id="gallery_coll_detail_addcart">
                                <a href="cart.php?id=<?php echo $fId; ?>" title="add to cart">add to cart</a>
                            </div>
                            <div id="gallery_product_coll_list">
                                <div id="gallery_product_coll_list_prev_bt">
                                    <img src="images/prev_bt2.jpg" alt="Previous" class="img_link <?php if($i<4){ echo 'display_none';} ?>" id="prev_bt2" />
                                </div>
                                <div id="gallery_product_coll_list_">
                                    <ul>
                                        <?php echo $collectGroupList; ?>
                                    </ul>
                                </div>
                                <div id="gallery_product_coll_list_next_bt">
                                    <img src="images/next_bt2.jpg" alt="Next" class="img_link <?php if($i<4){ echo 'display_none';} ?>" id="next_bt2" />
                                </div>
                                <div class="clear">&nbsp;</div>
                        </div>
                        </div>
                        <div class="clear">&nbsp;</div>
                    </div>
                    <div id="gallery_coll_detail_noproduct" <?php if($y==0){ echo 'style="display:block;"';} ?>>
                        <?php echo $status_msg['no_product_in_collection']; ?>
                    </div>
                    <div id="gallery_coll_detail_ajax">
                        <img src="images/ajax_indicator_01.gif" />
                    </div>
                </div>
                
                
                <?php echo $collectionList; ?>
                
                
            </div>
            <div class="clear">&nbsp;</div>
            <div id="sdfsdfsdf"></div>
<?php
    include('footer.php');
?>
<script type="text/javascript" src="js/jcarousellite_1.0.1.min.js"></script>
<script type="text/javascript" src="js/jquery.tinyscrollbar.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo-min.js"></script>
<script>
    $(function() {
        $('.afancybox').fancybox({
            'autoScale' : false
        });
        
        $("#gallery_coll_list_").jCarouselLite({
            btnNext: "#next_bt",
            btnPrev: "#prev_bt",
            visible:4
        });
        
        <?php if($i>=3){ ?>
        $("#gallery_product_coll_list_").jCarouselLite({
            btnNext: "#next_bt2",
            btnPrev: "#prev_bt2",
            visible:3
        });
        <?php } ?>
        
        $('#gallery_coll_detail_desc').tinyscrollbar({
            sizethumb:'30'
        });
        
        $('.select_coll_id').live('click',function(){
            $('#gallery_coll_detail_ajax').css('display','block');
            var cid = $(this).attr('id');
            var cslogan = $(this).attr('title');
            var ctitle = $(this).parent().find('p').html();
            
            $.post('function/load_collection.php','cid='+cid,function(data){
                //if(data.useraccess==1){
                    $('#gallery_coll_detail_ h2').html(ctitle);
                    $('#gallery_coll_detail_ h3').html(cslogan);
                    
                    $('#gallery_coll_detail_img a').attr('href',data.fImg);
                    $('#gallery_coll_detail_img a').attr('title',data.fTitle);
                    $('#gallery_coll_detail_img img').attr('src',data.fImg);
                    $('#gallery_coll_detail_img img').attr('alt',data.fTitle);
                    $('#gallery_coll_detail_desc .overview').html(data.fDetail);
                    $('#gallery_coll_detail_addcart a').attr('href','cart.php?id='+data.fId);
                    $('#gallery_product_coll_list_').html(data.collectGroupList);
                    
                    $('#gallery_coll_detail_ajax').css('display','none');
                    $('#gallery_coll_detail_x').css('display','block');
                    $('#gallery_coll_detail_noproduct').css('display','none');
                    $("#gallery_product_coll_list_").jCarouselLite({
                        btnNext: "#next_bt2",
                        btnPrev: "#prev_bt2",
                        visible:3
                    });
                    $('#gallery_coll_detail_desc').tinyscrollbar({
                        sizethumb:'30'
                    });
                    if(data.product<3){
                        $('#gallery_product_coll_list_prev_bt,#gallery_product_coll_list_next_bt').css('display','none');
                    }else{
                        $('#gallery_product_coll_list_prev_bt,#gallery_product_coll_list_next_bt').css('display','block');
                    }
                    $.scrollTo( '#gallery_coll_detail_x' , 500);
                //}else{
                //    $('#gallery_coll_detail_ajax').css('display','none');
                //    alert('<?php echo $status_msg['must_login']; ?>');
                //    $('.login_box #email').focus();
                //    $.scrollTo( '#header' , 500);
                //}
            },'json');
            
        });
        
        $('#gallery_product_coll_list_ ul li').live('click',function(){
            $('#gallery_coll_detail_ajax').css('display','block');
            $('#gallery_coll_detail_img img').attr('src',$(this).find('img').attr('src'));
            $('#gallery_coll_detail_img a').attr('href',$(this).find('img').attr('src'));
            $('#gallery_coll_detail_addcart a').attr('href','cart.php?id='+$(this).attr('id'));
            $('#gallery_coll_detail_ajax').css('display','none');
        });
    });
</script>